package com.swizipuremvc.core
{
	import mx.rpc.events.FaultEvent;
	import mx.utils.StringUtil;

	public class GlobalErrorHandler
	{
		
		
		public var globalErrors:Array = [];
		
		public function getGlobalError(event:FaultEvent):GlobalError
		{
			//fault.rootCause.message
			
			var globalError:GlobalError = new GlobalError();
			globalError.message = "cannot connect to Server";
			globalError.title = "Connection Error";
			
			
			
			if(event != null && event.fault != null && event.fault.rootCause != null && event.fault.rootCause.hasOwnProperty("message"))
			{
				var code:String = event.fault.rootCause.message;
				for each(var global:GlobalError in this.globalErrors)
				{
					if(global.code == StringUtil.trim(code))
					{
						return global;
					}
				}
			}
			
			return globalError;
			
		}
	}
}